﻿Public Class FrmDisposal
    Private x_disposal As X_Disposal
    Private x_disposal_old As X_Disposal

    Private _parentForm As SuperForm
    Private _parentObj As PO

    Public Sub New(ByVal xdisposal As X_Disposal, ByVal parentObj As PO, ByVal parentForm As SuperForm)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me._parentForm = parentForm
        Me._parentObj = parentObj

        Me.x_disposal = xdisposal
        If (Not Me._parentObj Is Nothing) Then
            Me.x_disposal.setValue(I_Repair.ColumnName_MaTS, Me._parentObj.getValue(I_TSCD.ColumnName_MaSO))
            Me.x_disposal.setValue(I_Repair.ColumnName_parentID, Me._parentObj.getValue(I_TSCD.ColumnName_id))
            Me.x_disposal.setValue(I_Repair.ColumnName_FAType, Me._parentObj.getValue(I_TSCD.ColumnName_FAType))
            Me.x_disposal.setValue(I_Repair.ColumnName_Status, CONSTANT.STATUS._DRAFTS)
        End If

        Me.x_disposal_old = Me.x_disposal


        ''Viet: Đổ dữ liệu lên Combobox
        Dim sqlWhere = "" & I_Council.ColumnName_Type & " = '" & COUNCIL_TYPE._DISPOSAL & "'"
        Dim da As New DataTable
        da = New Query(New X_Council(-1), sqlWhere).dataTable
        Me.cbHoiDongTL.DisplayMember = I_Council.ColumnName_Display
        Me.cbHoiDongTL.ValueMember = I_Council.ColumnName_id
        Me.cbHoiDongTL.DataSource = da
        Me.cbHoiDongTL.SelectedIndex = 0
        ini()

    End Sub

    Public Function ini() As Boolean

        Me.dtpThoiGian.Text = Me.x_disposal_old.getValue(I_Disposal.ColumnName_ThoiGian)
        Me.txtNguyenGia.Text = Me.x_disposal_old.getValue(I_Disposal.ColumnName_NguyenGia)
        Me.txtHaoMon.Text = Me.x_disposal_old.getValue(I_Disposal.ColumnName_SoHaoMon)
        Me.txtGiaTriConLai.Text = Me.x_disposal_old.getValue(I_Disposal.ColumnName_GiaTriConLai)
        Me.txtNoiDungTL.Text = Me.x_disposal_old.getValue(I_Disposal.ColumnName_NoiDungTL)
        Me.txtChiPhiTL.Text = Me.x_disposal_old.getValue(I_Disposal.ColumnName_ChiPhiTL)
        Me.cbHoiDongTL.Text = Me.x_disposal_old.getValue(I_Disposal.ColumnName_HDThanhLy)

    End Function


    Private Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        ini()
    End Sub


    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub


    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

        Me.x_disposal.setValue(I_Disposal.ColumnName_ThoiGian, Me.dtpThoiGian.Text)
        Me.x_disposal.setValue(I_Disposal.ColumnName_NguyenGia, Me.txtNguyenGia.Text)
        Me.x_disposal.setValue(I_Disposal.ColumnName_SoHaoMon, Me.txtHaoMon.Text)
        Me.x_disposal.setValue(I_Disposal.ColumnName_GiaTriConLai, Me.txtGiaTriConLai.Text)
        Me.x_disposal.setValue(I_Disposal.ColumnName_NoiDungTL, Me.txtNoiDungTL.Text)
        Me.x_disposal.setValue(I_Disposal.ColumnName_ChiPhiTL, Me.txtChiPhiTL.Text)
        Me.x_disposal.setValue(I_Disposal.ColumnName_HDThanhLy, Me.cbHoiDongTL.SelectedValue)

        Me.x_disposal.save(True)

        Me._parentForm.loadDisposal()
        Me._parentForm.specifyCorrespondingDisposal()

        Me.Close()

    End Sub
End Class